home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-20 | 5.9 KB | 207 lines | [TEXT/MPS ] |
- #
- # PatchWorks -
- # Applies changes described in a set of patch files.
- #
- # Usage:
- # PatchWorks [-create | -restore]
- # - create # creates a set of patch files
- # - restore # restores patched files from saved originals
- #
- # Returns:
- # Not much
- #
- # To create the patch file, use:
- #
- # Compare -v <newfile> <oldfile> > <oldfile>.Df
- #
- # Or
- #
- # PatchWorks -create
- #
- # To apply the patches, use:
- #
- # PatchWorks
- #
- # and select the directories containing the files to be converted and the
- # patch files. The script will perform the conversion and rename the
- # original file to "<file>.ol".
- #
- # If, for some reason, you need to revert to your original set of source
- # files, you can use "PatchWorks -restore". This will replace the patched
- # files with the saved <file>.ol files.
- #
- #
- # Change History
- # 6/30/90 lsr First release.
- # 8/01/90 kaar Added "-create" option to create patch files. Put file
- # extensions into variables. Made to work with nested folders
- # (both during creation of the patch files, and during
- # application of changes).
- # 8/23/90 kaar Allow people to cancel from StdFile. Made about 25% faster
- # by not switching targets. Hopefully fixed infinite loop bug.
- # 8/29/90 kaar Added restore option (replaces files with any .ol versions)
- # Allow for missing source files (i.e, files that need to be
- # patched). This can happen if people haven't installed the
- # C++ support.
- # 8/30/90 kaar Have -create ask for folder names, rather than hard-coding
- # them. Remove the resource forks of the patch files to make
- # them smaller for electronic transmission.
- # 9/19/90 kaar Name of the patches folder is no longer hard-coded. It is
- # now "<original folder name> Patches". Send diagnostic output
- # of "which" to bit bucket.
- #
-
- Set Exit 0
-
- set DiffSuffix ".df" # Gotta be only 3 chars so we can tack it onto "Build Rules and Dependencies" and still stay under 32 characters.
- set OriginalSuffix ".ol"
- set ConvertedSuffix ".cv"
-
- If "{1}" == "-create"
-
- Set originalFolder `getfilename -d -m "Select original folder." || Echo '""'`
- Exit If "{originalFolder}" == ""
- Set updatedFolder `getfilename -d -m "Select udpated folder." || Echo '""'`
- Exit If "{updatedFolder}" == ""
- Set patchesFolder `getfilename -d -m "Select location for patches folder." || Echo '""'`
- Exit If "{patchesFolder}" == ""
-
- (Evaluate "{originalFolder}" =~ /≈:(≈)®1:/) > Dev:Null
- Set patchesFolder "{patchesFolder}{®1} Patches:"
-
- For fullFileName in `files -r -s -f "{originalFolder}" -t TEXT`
- (Evaluate "{fullFileName}" =~ /{originalFolder}(≈)®1/) > Dev:Null
- Set fileName "{®1}"
-
- (Evaluate "{patchesFolder}{fileName}" =~ /(≈:)®1≈/) > Dev:Null
- If `Exists -d "{®1}"` == ""
- Set oldDirectory `Directory` ∑ Dev:Null # save the directory
- Set partialPath "{patchesFolder}{fileName}"
- Loop
- (Evaluate "{partialPath}" =~ /(:*[¬:]+)®1(≈)®2/) > Dev:Null
- Break If "{®2}" == ""
- Set partialPath "{®2}"
- If `Exists -d "{®1}:"` == ""
- Set dir "`Directory -q`"
- (Evaluate "{dir}" =~ /(≈)®3:/) > Dev:Null
- Echo "Creating ‘{®3}{®1}:’"
- NewFolder "{®1}:"
- End
- Directory "{®1}:"
- End
- Directory "{oldDirectory}" # restore the original directory
- End
-
- Echo -n "Comparing {fileName}."
- Compare -v "{updatedFolder}{fileName}" "{originalFolder}{fileName}" > "{patchesFolder}{fileName}{DiffSuffix}" ≥≥ Dev:Null
- Set savedStatus "{Status}"
- If "{savedStatus}" != 2
- If "{savedStatus}" == 0
- Echo -n " Files are the same."
- Else
- Echo -n " Compare error #{savedStatus}."
- End
- Echo " Deleting ..."
- Delete -y "{patchesFolder}{fileName}{DiffSuffix}"
- Else
- Echo
- If "`which NukeResForks ≥ Dev:Null`" != ""
- NukeResForks "{patchesFolder}{fileName}{DiffSuffix}"
- End
- End
- End
-
- Else If "{1}" == "-restore"
- Set iDir `getfilename -d -m 'Select MacApp folder to restore.'`
- Exit If "{iDir}" == ""
- For file In `files -r -s -f "{iDir}" -t TEXT`
- If "{file}" =~ /{iDir}(≈)®1{OriginalSuffix}/
- Set src "{iDir}{®1}"
- Set Original "{src}{OriginalSuffix}"
-
- Echo "Restoring {src}."
-
- Delete -y "{src}"
- Rename "{Original}" "{src}"
- End
- End
-
- Else
- Set iDir `getfilename -d -m 'Select folder to be patched.'`
- Exit If "{iDir}" == ""
- Set dDir `getfilename -d -m 'Select folder with the patches.'`
- Exit If "{dDir}" == ""
-
- For file In `files -r -s -f "{dDir}" -t TEXT`
- If "{file}" =~ /{dDir}(≈)®1{DiffSuffix}/
- Set src "{iDir}{®1}"
- Set diff "{file}"
- Set cvt "{src}{ConvertedSuffix}"
-
- Duplicate "{src}" "{cvt}" ∑∑ Dev:Null
-
- If "{Status}" != 0
-
- Echo "Couldn’t find {cvt}. Skipping it."
-
- Else
-
- Echo "Converting {src}."
-
- Open "{cvt}"
- Target "{diff}"; find ∞
-
- Loop
-
- #
- # Look for the next change to make. Note that we check three times to see
- # if we've reached the top of the file (remember, we're searching backwards).
- # This is because a backwards search doesn't always flag the fact that it
- # failed; sometimes it does, and sometimes it doesn't. So I threw in two
- # more checks just to make sure. Without these checks, we can sometimes
- # enter into an infinite loop.
- #
-
- Find \•≈∂(File\ || Break
-
- (Evaluate "`Catenate §`" =~ /≈∂(File/) > Dev:Null || Break
- Set change "`Catenate §`"
- Break If "{change}" !~ /≈∂(File/
-
- Find /Line [¬;]+;/
- (Evaluate "`Catenate §`" =~ /Line (≈)®1;/) > Dev:Null
- Set newSel "{®1}"
-
- Find /Line ≈∂)/
- (Evaluate "`Catenate §`" =~ /Line (≈)®1∂)/) > Dev:Null
- Set oldSel "{®1}"
-
- Find Δ!1
- If "{newSel}" =~ /([0-9]+)®8:([0-9]+)®9/
- Copy §:!`Evaluate "{®9}"-"{®8}"`
- Else
- Copy !0
- End
-
- If "{change}" =~ /Extra lines in 2≈/
- Clear {oldSel} "{cvt}"
- Else
- Find {oldSel} "{cvt}"
- Paste § "{cvt}"
- End
-
- Find \•≈∂(File≈∞\
-
- End # Loop
-
- Close -y "{cvt}"
- Close -n "{diff}"
-
- Rename "{src}" "{src}{OriginalSuffix}"
- Rename "{cvt}" "{src}"
- End # If {Status}
- End ∑∑ "{WorkSheet}" # If {file}
- End # For file
- End
-
- Set Exit 1